package cn.kgc.javaweb.servlet;

import cn.kgc.javaweb.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: mosin
 * @version: v1.0  2022/11/6
 */
@WebServlet("/user")
public class UserServlet  extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String username = req.getParameter("username");
        User user = new User();
        user.setUsername(username);
        //用户登录成功 将用户信息存储在session对象中
        req.getSession().setAttribute("user", user);
        System.out.println("用户的操作请求被接收");

        resp.sendRedirect(req.getContextPath()+"/user.jsp");

    }
}
